home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-12 | 16.7 KB | 543 lines | [TEXT/PJMM] |
- unit Sound;
-
- { Pascal Interface to the Macintosh Libraries }
-
- { Copyright © Apple Computer Inc. }
- { All Rights Reserved }
-
- { Adapted for use with THINK Pascal 4.0.x by Marco Piovanelli }
-
- interface
- uses
- Types;
-
- const
-
- twelfthRootTwo = 1.05946309434;
- soundListRsrc = 'snd '; {Resource type used by Sound Manager}
- rate44khz = $AC440000; {44100.00000 in fixed-point}
- rate22050hz = $56220000; {22050.00000 in fixed-point}
- rate22khz = $56EE8BA3; {22254.54545 in fixed-point}
- rate11khz = $2B7745D1; {11127.27273 in fixed-point}
- rate11025hz = $2B110000; {11025.00000 in fixed-point}
-
- {synthesizer numbers for SndNewChannel}
- squareWaveSynth = 1; {square wave synthesizer}
- waveTableSynth = 3; {wave table synthesizer}
- sampledSynth = 5; {sampled sound synthesizer}
-
- {old Sound Manager MACE synthesizer numbers}
- MACE3snthID = 11;
- MACE6snthID = 13;
- kMiddleC = 60; {MIDI note value for middle C}
- kSimpleBeepID = 1; {reserved resource ID for Simple Beep}
- kFullVolume = $0100; {1.0, setting for full hardware output volume}
- kNoVolume = 0; {setting for no sound volume}
-
- {command numbers for SndDoCommand and SndDoImmediate}
- nullCmd = 0;
- initCmd = 1;
- freeCmd = 2;
- quietCmd = 3;
- flushCmd = 4;
- reInitCmd = 5;
- waitCmd = 10;
- pauseCmd = 11;
- resumeCmd = 12;
- callBackCmd = 13;
-
- syncCmd = 14;
- availableCmd = 24;
- versionCmd = 25;
- totalLoadCmd = 26;
- loadCmd = 27;
- freqDurationCmd = 40;
- restCmd = 41;
- freqCmd = 42;
- ampCmd = 43;
- timbreCmd = 44;
- getAmpCmd = 45;
- volumeCmd = 46; {sound manager 3.0 or later only}
- getVolumeCmd = 47; {sound manager 3.0 or later only}
- waveTableCmd = 60;
- phaseCmd = 61;
-
- soundCmd = 80;
- bufferCmd = 81;
- rateCmd = 82;
- continueCmd = 83;
- doubleBufferCmd = 84;
- getRateCmd = 85;
- rateMultiplierCmd = 86;
- getRateMultiplierCmd = 87;
- sizeCmd = 90;
- convertCmd = 91;
- stdQLength = 128;
- dataOffsetFlag = $8000;
-
- {channel initialization parameters}
- initChanLeft = $0002; {left stereo channel}
- initChanRight = $0003; {right stereo channel}
- initNoInterp = $0004; {no linear interpolation}
- initNoDrop = $0008; {no drop-sample conversion}
- initMono = $0080; {monophonic channel}
- initStereo = $00C0; {stereo channel}
- initMACE3 = $0300; {MACE 3:1}
- initMACE6 = $0400; {MACE 6:1}
- initPanMask = $0003; {mask for right/left pan values}
- initSRateMask = $0030; {mask for sample rate values}
- initStereoMask = $00C0; {mask for mono/stereo values}
- initCompMask = $FF00; {mask for compression IDs}
- kUseOptionalOutputDevice = -1; {only for Sound Manager 3.0 or later}
- notCompressed = 0; {compression ID's}
- fixedCompression = -1; {compression ID for fixed-sized compression}
- variableCompression = -2; {compression ID for variable-sized compression}
- twoToOne = 1;
- eightToThree = 2;
- threeToOne = 3;
- sixToOne = 4;
-
- stdSH = $00; {Standard sound header encode value}
- extSH = $FF; {Extended sound header encode value}
- cmpSH = $FE; {Compressed sound header encode value}
-
- outsideCmpSH = 0; {MACE constants}
- insideCmpSH = 1;
- aceSuccess = 0;
- aceMemFull = 1;
- aceNilBlock = 2;
- aceBadComp = 3;
- aceBadEncode = 4;
- aceBadDest = 5;
- aceBadCmd = 6;
- sixToOnePacketSize = 8;
- threeToOnePacketSize = 16;
- stateBlockSize = 64;
- leftOverBlockSize = 32;
- firstSoundFormat = $0001; {general sound format}
- secondSoundFormat = $0002; {special sampled sound format (HyperCard)}
- dbBufferReady = $00000001; {double buffer is filled}
- dbLastBuffer = $00000004; {last double buffer to play}
- sysBeepDisable = $0000; {SysBeep() enable flags}
- sysBeepEnable = $0001;
- unitTypeNoSelection = $FFFF; {unitTypes for AudioSelection.unitType}
- unitTypeSeconds = $0000;
-
- { unsigned fixed-point number }
-
- type
- UnsignedFixed = LONGINT;
-
- SndCommand = packed record
- cmd: INTEGER;
- param1: INTEGER;
- param2: LONGINT;
- end;
- SndChannelPtr = ^SndChannel;
-
- SndCallBackProcPtr = ProcPtr; { PROCEDURE SndCallBack(chan: SndChannelPtr; VAR cmd: SndCommand); }
- SndCallBackUPP = UniversalProcPtr;
-
- SndChannel = packed record
- nextChan: ^SndChannel;
- firstMod: Ptr; { reserved for the Sound Manager }
- callBack: SndCallBackUPP;
- userInfo: LONGINT;
- wait: LONGINT; { The following is for internal Sound Manager use only.}
- cmdInProgress: SndCommand;
- flags: INTEGER;
- qLength: INTEGER;
- qHead: INTEGER;
- qTail: INTEGER;
- queue: array[0..127] of SndCommand;
- end;
- {MACE structures}
- StateBlock = record
- stateVar: array[0..63] of INTEGER;
- end;
- StateBlockPtr = ^StateBlock;
-
- LeftOverBlock = record
- count: LONGINT;
- sampleArea: packed array[0..31] of CHAR;
- end;
- LeftOverBlockPtr = ^LeftOverBlock;
-
- ModRef = record
- modNumber: INTEGER;
- modInit: LONGINT;
- end;
- SndListResource = record
- format: INTEGER;
- numModifiers: INTEGER;
- modifierPart: array[0..0] of ModRef; {This is a variable length array}
- numCommands: INTEGER;
- commandPart: array[0..0] of SndCommand; {This is a variable length array}
- dataPart: packed array[0..0] of CHAR; {This is a variable length array}
- end;
- SndListPtr = ^SndListResource;
-
- SndListHndl = ^SndListPtr;
- SndListHandle = ^SndListPtr;
-
- {HyperCard sound resource format}
- Snd2ListResource = record
- format: INTEGER;
- refCount: INTEGER;
- numCommands: INTEGER;
- commandPart: array[0..0] of SndCommand; {This is a variable length array}
- dataPart: packed array[0..0] of CHAR; {This is a variable length array}
- end;
- Snd2ListPtr = ^Snd2ListResource;
-
- Snd2ListHndl = ^Snd2ListPtr;
- Snd2ListHandle = ^Snd2ListPtr;
-
- SoundHeader = packed record
- samplePtr: Ptr; {if NIL then samples are in sampleArea}
- length: LONGINT; {length of sound in bytes}
- sampleRate: UnsignedFixed; {sample rate for this sound}
- loopStart: LONGINT; {start of looping portion}
- loopEnd: LONGINT; {end of looping portion}
- encode: CHAR; {header encoding}
- baseFrequency: CHAR; {baseFrequency value}
- sampleArea: packed array[0..0] of CHAR; {space for when samples follow directly}
- end;
- SoundHeaderPtr = ^SoundHeader;
-
- CmpSoundHeader = packed record
- samplePtr: Ptr; {if nil then samples are in sample area}
- numChannels: LONGINT; {number of channels i.e. mono = 1}
- sampleRate: UnsignedFixed; {sample rate in Apples Fixed point representation}
- loopStart: LONGINT; {loopStart of sound before compression}
- loopEnd: LONGINT; {loopEnd of sound before compression}
- encode: CHAR; {data structure used , stdSH, extSH, or cmpSH}
- baseFrequency: CHAR; {same meaning as regular SoundHeader}
- numFrames: LONGINT; {length in frames ( packetFrames or sampleFrames )}
- AIFFSampleRate: extended80; {IEEE sample rate}
- markerChunk: Ptr; {sync track}
- format: OSType; {data format type, was futureUse1}
- futureUse2: LONGINT; {reserved by Apple}
- stateVars: StateBlockPtr; {pointer to State Block}
- leftOverSamples: LeftOverBlockPtr; {used to save truncated samples between compression calls}
- compressionID: INTEGER; {0 means no compression, non zero means compressionID}
- packetSize: INTEGER; {number of bits in compressed sample packet}
- snthID: INTEGER; {resource ID of Sound Manager snth that contains NRT C/E}
- sampleSize: INTEGER; {number of bits in non-compressed sample}
- sampleArea: packed array[0..0] of CHAR; {space for when samples follow directly}
- end;
- CmpSoundHeaderPtr = ^CmpSoundHeader;
-
- ExtSoundHeader = packed record
- samplePtr: Ptr; {if nil then samples are in sample area}
- numChannels: LONGINT; {number of channels, ie mono = 1}
- sampleRate: UnsignedFixed; {sample rate in Apples Fixed point representation}
- loopStart: LONGINT; {same meaning as regular SoundHeader}
- loopEnd: LONGINT; {same meaning as regular SoundHeader}
- encode: CHAR; {data structure used , stdSH, extSH, or cmpSH}
- baseFrequency: CHAR; {same meaning as regular SoundHeader}
- numFrames: LONGINT; {length in total number of frames}
- AIFFSampleRate: extended80; {IEEE sample rate}
- markerChunk: Ptr; {sync track}
- instrumentChunks: Ptr; {AIFF instrument chunks}
- AESRecording: Ptr;
- sampleSize: INTEGER; {number of bits in sample}
- futureUse1: INTEGER; {reserved by Apple}
- futureUse2: LONGINT; {reserved by Apple}
- futureUse3: LONGINT; {reserved by Apple}
- futureUse4: LONGINT; {reserved by Apple}
- sampleArea: packed array[0..0] of CHAR; {space for when samples follow directly}
- end;
- ExtSoundHeaderPtr = ^ExtSoundHeader;
-
- ConversionBlock = record
- destination: INTEGER;
- unused: INTEGER;
- inputPtr: CmpSoundHeaderPtr;
- outputPtr: CmpSoundHeaderPtr;
- end;
- ConversionBlockPtr = ^ConversionBlock;
-
- SMStatus = packed record
- smMaxCPULoad: INTEGER;
- smNumChannels: INTEGER;
- smCurCPULoad: INTEGER;
- end;
- SMStatusPtr = ^SMStatus;
-
- SCStatus = record
- scStartTime: UnsignedFixed;
- scEndTime: UnsignedFixed;
- scCurrentTime: UnsignedFixed;
- scChannelBusy: BOOLEAN;
- scChannelDisposed: BOOLEAN;
- scChannelPaused: BOOLEAN;
- scUnused: BOOLEAN;
- scChannelAttributes: LONGINT;
- scCPULoad: LONGINT;
- end;
- SCStatusPtr = ^SCStatus;
-
- AudioSelection = packed record
- unitType: LONGINT;
- selStart: UnsignedFixed;
- selEnd: UnsignedFixed;
- end;
- FilePlayCompletionProcPtr = ProcPtr; { PROCEDURE FilePlayCompletion(chan: SndChannelPtr); }
- FilePlayCompletionUPP = UniversalProcPtr;
-
- const
- uppFilePlayCompletionProcInfo = $000000C0; { PROCEDURE (4 byte param); }
-
- function NewFilePlayCompletionProc (userRoutine: FilePlayCompletionProcPtr): FilePlayCompletionUPP;
- inline
- $2E9F;
-
- procedure CallFilePlayCompletionProc (chan: SndChannelPtr;
- userRoutine: FilePlayCompletionUPP);
- inline
- $205F, $4E90;
-
- type
- AudioSelectionPtr = ^AudioSelection;
-
- SndDoubleBuffer = packed record
- dbNumFrames: LONGINT;
- dbFlags: LONGINT;
- dbUserInfo: array[0..1] of LONGINT;
- dbSoundData: packed array[0..0] of CHAR;
- end;
- SndDoubleBufferPtr = ^SndDoubleBuffer;
-
- SndDoubleBackProcPtr = ProcPtr; { PROCEDURE SndDoubleBack(channel: SndChannelPtr; doubleBufferPtr: SndDoubleBufferPtr); }
- SndDoubleBackUPP = UniversalProcPtr;
-
- const
- uppSndDoubleBackProcInfo = $000003C0; { PROCEDURE (4 byte param, 4 byte param); }
-
- function NewSndDoubleBackProc (userRoutine: SndDoubleBackProcPtr): SndDoubleBackUPP;
- inline
- $2E9F;
-
- procedure CallSndDoubleBackProc (channel: SndChannelPtr;
- doubleBufferPtr: SndDoubleBufferPtr;
- userRoutine: SndDoubleBackUPP);
- inline
- $205F, $4E90;
-
- type
- SndDoubleBufferHeader = packed record
- dbhNumChannels: INTEGER;
- dbhSampleSize: INTEGER;
- dbhCompressionID: INTEGER;
- dbhPacketSize: INTEGER;
- dbhSampleRate: UnsignedFixed;
- dbhBufferPtr: array[0..1] of SndDoubleBufferPtr;
- dbhDoubleBack: SndDoubleBackUPP;
- end;
- SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
-
- SndDoubleBufferHeader2 = packed record
- dbhNumChannels: INTEGER;
- dbhSampleSize: INTEGER;
- dbhCompressionID: INTEGER;
- dbhPacketSize: INTEGER;
- dbhSampleRate: UnsignedFixed;
- dbhBufferPtr: array[0..1] of SndDoubleBufferPtr;
- dbhDoubleBack: SndDoubleBackUPP;
- dbhFormat: OSType;
- end;
- SndDoubleBufferHeader2Ptr = ^SndDoubleBufferHeader2;
-
- SoundInfoList = packed record
- count: INTEGER;
- infoHandle: Handle;
- end;
- SoundInfoListPtr = ^SoundInfoList;
-
- CompressionInfo = record
- recordSize: LONGINT;
- format: OSType;
- compressionID: INTEGER;
- samplesPerPacket: INTEGER;
- bytesPerPacket: INTEGER;
- bytesPerFrame: INTEGER;
- bytesPerSample: INTEGER;
- futureUse1: INTEGER;
- end;
- CompressionInfoPtr = ^CompressionInfo;
-
- CompressionInfoHandle = ^CompressionInfoPtr;
-
- function SndDoCommand (chan: SndChannelPtr; {CONST}
- var cmd: SndCommand;
- noWait: BOOLEAN): OSErr;
- inline
- $A803;
- function SndDoImmediate (chan: SndChannelPtr; {CONST}
- var cmd: SndCommand): OSErr;
- inline
- $A804;
- function SndNewChannel (var chan: SndChannelPtr;
- synth: INTEGER;
- init: LONGINT;
- userRoutine: SndCallBackUPP): OSErr;
- inline
- $A807;
- function SndDisposeChannel (chan: SndChannelPtr;
- quietNow: BOOLEAN): OSErr;
- inline
- $A801;
- function SndPlay (chan: SndChannelPtr;
- sndHdl: SndListHandle;
- async: BOOLEAN): OSErr;
- inline
- $A805;
- function SndAddModifier (chan: SndChannelPtr;
- modifier: Ptr;
- id: INTEGER;
- init: LONGINT): OSErr;
- inline
- $A802;
- function SndControl (id: INTEGER;
- var cmd: SndCommand): OSErr;
- inline
- $A806;
-
- { Sound Manager 2.0 and later, uses _SoundDispatch }
- function SndSoundManagerVersion: NumVersion;
- inline
- $203C, $000C, $0008, $A800;
- function SndStartFilePlay (chan: SndChannelPtr;
- fRefNum: INTEGER;
- resNum: INTEGER;
- bufferSize: LONGINT;
- theBuffer: univ Ptr;
- theSelection: AudioSelectionPtr;
- theCompletion: FilePlayCompletionUPP;
- async: BOOLEAN): OSErr;
- inline
- $203C, $0D00, $0008, $A800;
- function SndPauseFilePlay (chan: SndChannelPtr): OSErr;
- inline
- $203C, $0204, $0008, $A800;
- function SndStopFilePlay (chan: SndChannelPtr;
- quietNow: BOOLEAN): OSErr;
- inline
- $203C, $0308, $0008, $A800;
- function SndChannelStatus (chan: SndChannelPtr;
- theLength: INTEGER;
- theStatus: SCStatusPtr): OSErr;
- inline
- $203C, $0010, $0008, $A800;
- function SndManagerStatus (theLength: INTEGER;
- theStatus: SMStatusPtr): OSErr;
- inline
- $203C, $0014, $0008, $A800;
- procedure SndGetSysBeepState (var sysBeepState: INTEGER);
- inline
- $203C, $0018, $0008, $A800;
- function SndSetSysBeepState (sysBeepState: INTEGER): OSErr;
- inline
- $203C, $001C, $0008, $A800;
- function SndPlayDoubleBuffer (chan: SndChannelPtr;
- theParams: SndDoubleBufferHeaderPtr): OSErr;
- inline
- $203C, $0020, $0008, $A800;
-
- { MACE compression routines }
- function MACEVersion: NumVersion;
- inline
- $203C, $0000, $0010, $A800;
- procedure Comp3to1 (inBuffer: univ Ptr;
- outBuffer: univ Ptr;
- cnt: LONGINT;
- inState: univ Ptr;
- outState: univ Ptr;
- numChannels: LONGINT;
- whichChannel: LONGINT);
- inline
- $203C, $0004, $0010, $A800;
- procedure Exp1to3 (inBuffer: univ Ptr;
- outBuffer: univ Ptr;
- cnt: LONGINT;
- inState: univ Ptr;
- outState: univ Ptr;
- numChannels: LONGINT;
- whichChannel: LONGINT);
- inline
- $203C, $0008, $0010, $A800;
- procedure Comp6to1 (inBuffer: univ Ptr;
- outBuffer: univ Ptr;
- cnt: LONGINT;
- inState: univ Ptr;
- outState: univ Ptr;
- numChannels: LONGINT;
- whichChannel: LONGINT);
- inline
- $203C, $000C, $0010, $A800;
- procedure Exp1to6 (inBuffer: univ Ptr;
- outBuffer: univ Ptr;
- cnt: LONGINT;
- inState: univ Ptr;
- outState: univ Ptr;
- numChannels: LONGINT;
- whichChannel: LONGINT);
- inline
- $203C, $0010, $0010, $A800;
-
- { Sound Manager 3.0 and later calls }
- function GetSysBeepVolume (var level: LONGINT): OSErr;
- inline
- $203C, $0224, $0018, $A800;
- function SetSysBeepVolume (level: LONGINT): OSErr;
- inline
- $203C, $0228, $0018, $A800;
- function GetDefaultOutputVolume (var level: LONGINT): OSErr;
- inline
- $203C, $022C, $0018, $A800;
- function SetDefaultOutputVolume (level: LONGINT): OSErr;
- inline
- $203C, $0230, $0018, $A800;
- function GetSoundHeaderOffset (sndHandle: SndListHandle;
- var offset: LONGINT): OSErr;
- inline
- $203C, $0404, $0018, $A800;
- function UnsignedFixedMulDiv (value: UnsignedFixed;
- multiplier: UnsignedFixed;
- divisor: UnsignedFixed): UnsignedFixed;
- inline
- $203C, $060C, $0018, $A800;
- function GetCompressionInfo (compressionID: INTEGER;
- format: OSType;
- numChannels: INTEGER;
- sampleSize: INTEGER;
- cp: CompressionInfoPtr): OSErr;
- inline
- $203C, $0710, $0018, $A800;
- function SetSoundPreference (theType: OSType;
- var name: Str255;
- settings: Handle): OSErr;
- inline
- $203C, $0634, $0018, $A800;
- function GetSoundPreference (theType: OSType;
- var name: Str255;
- settings: Handle): OSErr;
- inline
- $203C, $0638, $0018, $A800;
-
- const
- uppSndCallBackProcInfo = $000003C0; { PROCEDURE (4 byte param, 4 byte param); }
-
- function NewSndCallBackProc (userRoutine: SndCallBackProcPtr): SndCallBackUPP;
- inline
- $2E9F;
-
- procedure CallSndCallBackProc (chan: SndChannelPtr;
- var cmd: SndCommand;
- userRoutine: SndCallBackUPP);
- inline
- $205F, $4E90;
-
- implementation
- end.